//
//  BundleShadowView.swift
//  FreeShadow
//
//  Created by hongyan.yang on 2021/9/13.
//

import UIKit

@IBDesignable
class BundleShadowView: UIView, ShadowView {
    
    lazy var shadow: NSShadow = {
        let shadow = NSShadow()
        shadow.shadowColor = UIColor.lightGray
        shadow.shadowOffset = CGSize(width: 0, height: 0)
        shadow.shadowBlurRadius = 15
        return shadow
    }()
    lazy var shadowPath: UIBezierPath = {
        let bezierPath = UIBezierPath()
        bezierPath.move(to: CGPoint(x: 146, y: 117.98))
        bezierPath.addCurve(to: CGPoint(x: 146.2, y: 191.61), controlPoint1: CGPoint(x: 146, y: 117.98), controlPoint2: CGPoint(x: 146.09, y: 150.06))
        bezierPath.addCurve(to: CGPoint(x: 177, y: 186), controlPoint1: CGPoint(x: 155.77, y: 187.98), controlPoint2: CGPoint(x: 166.15, y: 186))
        bezierPath.addCurve(to: CGPoint(x: 180.96, y: 186.09), controlPoint1: CGPoint(x: 178.33, y: 186), controlPoint2: CGPoint(x: 179.65, y: 186.03))
        bezierPath.addCurve(to: CGPoint(x: 264, y: 273), controlPoint1: CGPoint(x: 227.17, y: 188.16), controlPoint2: CGPoint(x: 264, y: 226.28))
        bezierPath.addCurve(to: CGPoint(x: 177, y: 360), controlPoint1: CGPoint(x: 264, y: 321.05), controlPoint2: CGPoint(x: 225.05, y: 360))
        bezierPath.addCurve(to: CGPoint(x: 146.62, y: 354.55), controlPoint1: CGPoint(x: 166.31, y: 360), controlPoint2: CGPoint(x: 156.07, y: 358.07))
        bezierPath.addCurve(to: CGPoint(x: 146.66, y: 375.73), controlPoint1: CGPoint(x: 146.64, y: 366.07), controlPoint2: CGPoint(x: 146.66, y: 373.74))
        bezierPath.addCurve(to: CGPoint(x: 146.52, y: 379.56), controlPoint1: CGPoint(x: 146.89, y: 375.73), controlPoint2: CGPoint(x: 146.52, y: 379.56))
        bezierPath.addCurve(to: CGPoint(x: 131.04, y: 389.87), controlPoint1: CGPoint(x: 146.52, y: 379.56), controlPoint2: CGPoint(x: 146.9, y: 388.07))
        bezierPath.addCurve(to: CGPoint(x: 43.07, y: 389.98), controlPoint1: CGPoint(x: 115.18, y: 391.68), controlPoint2: CGPoint(x: 74.2, y: 388.95))
        bezierPath.addCurve(to: CGPoint(x: 14.49, y: 381.61), controlPoint1: CGPoint(x: 13.33, y: 390.96), controlPoint2: CGPoint(x: 14.32, y: 382.62))
        bezierPath.addLine(to: CGPoint(x: 14, y: 378.78))
        bezierPath.addLine(to: CGPoint(x: 14, y: 117.98))
        bezierPath.addLine(to: CGPoint(x: 146, y: 117.98))
        bezierPath.addLine(to: CGPoint(x: 146, y: 117.98))
        bezierPath.close()
        return bezierPath
    }()
    var intrinsicSize: CGSize = CGSize(width: 278, height: 401)
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(origin: frame.origin,size: intrinsicSize))
        commonInit()
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
        commonInit()
    }
    private func commonInit(){
        backgroundColor = .clear
    }
    override func draw(_ rect: CGRect) {
        drawShadow(rect)
    }
}
